package com.sdtv.mediunfusion.mvp.ui.punch;

import android.text.TextUtils;
import android.util.Log;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.blankj.utilcode.util.LogUtils;
import com.sdtv.basemodule.base.BaseActivity;
import com.sdtv.mediunfusion.R;
import com.sdtv.mediunfusion.bean.PunchBean;
import com.sdtv.mediunfusion.utils.RouterPath;

import butterknife.BindView;

/**
 * 打卡详情页
 * --用户当天的打卡记录
 */
@Route(path = RouterPath.TO_PUNCHDETIAL_ACTIVITY)
public class PunchDetailActivity extends BaseActivity {


    @BindView(R.id.pd_timeView)
    TextView pdTimeView;
    @BindView(R.id.pd_placeView)
    TextView pdPlaceView;
    @BindView(R.id.pd_remarkView)
    TextView pdRemarkView;

    @Autowired(name = "select_calendar")
    PunchBean punchBean;
    //判断是上午还是下午
    @Autowired
    boolean isAm;


    @Override
    public int getLayoutId() {
        return R.layout.activity_punch_detail;
    }

    /**
     * 初始化页面布局
     */
    @Override
    public void initView() {

    }

    /**
     * 设置页面数据
     */
    @Override
    public void initData() {
        LogUtils.e("punchBean :" + punchBean);
        if (null != punchBean) {
            if (isAm) {
                showLogging(punchBean.getInStatus(), punchBean.getInTime(), punchBean.getInLocation(),
                        punchBean.getInRemarks());
            } else {
                //显示下午的打开记录 --下午
                showLogging(punchBean.getOutStatus(), punchBean.getOutTime(), punchBean.getOutLocation(),
                        punchBean.getOutRemarks());
            }
        } else {
            showNoLogging();
        }
    }


    /**
     * 显示暂无记录内容
     */
    private void showNoLogging() {
        pdTimeView.setTextColor(getResources().getColor(R.color.color_3333));
        pdPlaceView.setTextColor(getResources().getColor(R.color.color_3333));
        pdRemarkView.setTextColor(getResources().getColor(R.color.color_3333));

        pdTimeView.setText("无记录");
        pdPlaceView.setText("无记录");
        pdRemarkView.setText("无记录");
    }


    /**
     * 显示打卡记录
     */
    private void showLogging(String status, String time, String location, String remarks) {
        //1、显示打卡时间  --正常打卡以及未记录显示黑色 异常显示为红色
        //显示打开记录   判断打卡状态  正常：0， 迟到：1, 范围外: 2，既迟到又在范围外：3
        if (TextUtils.isEmpty(status)) {
            //为空表示没有打卡的数据记录   --
            showNoLogging();
        } else {
            if ("0".equals(status)) {
                pdTimeView.setTextColor(getResources().getColor(R.color.color_3333));
                pdPlaceView.setTextColor(getResources().getColor(R.color.color_3333));
            } else {
                pdTimeView.setTextColor(getResources().getColor(R.color.abnormal_punch_color));
                pdPlaceView.setTextColor(getResources().getColor(R.color.abnormal_punch_color));
            }
            if (!TextUtils.isEmpty(time)) {
                pdTimeView.setText(time);
            } else {
                pdTimeView.setText("无记录");
            }
            if (!TextUtils.isEmpty(location)) {
                pdPlaceView.setText(location);
            } else {
                pdPlaceView.setText("无记录");
            }
            if (!TextUtils.isEmpty(remarks)) {
                pdRemarkView.setText(remarks);
            } else {
                pdRemarkView.setText("无记录");
            }

        }
    }
}
